package gsb.android;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import modele.DAO;
import modele.Medecin;

/**
 *
 * @author amarchand
 */
public class ListeMed extends ListActivity {

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //on va chercher la vue
        setContentView(R.layout.listemed);
        TextView label = (TextView) findViewById(R.id.label);
        Intent inter = getIntent();

        // on va chercher le boutton
        Button button = (Button) findViewById(R.id.button);
        final EditText filtre = (EditText) findViewById(R.id.recherche);

        String numDep = inter.getStringExtra("numDep");
        label.setText(numDep);

        final List<Medecin> lesMeds = DAO.getLesMeds(numDep);
        MedAdapter adapter = new MedAdapter(lesMeds, this);
        setListAdapter(adapter);

        button.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                List<Medecin> medR = new ArrayList<Medecin>();

                for (Medecin leMed : lesMeds) {
                    if (leMed.getNom().startsWith(filtre.getText().toString())) {
                        medR.add(leMed);
                    }
                }
                MedAdapter adapter = new MedAdapter(medR,getApplicationContext());
                setListAdapter(adapter);
            }

        });

    }
}
